1
|
|
|
import { Locales } from "./localize"; |
2
|
|
|
import { Portal } from "../models/app"; |
3
|
|
|
|
4
|
|
|
/* eslint-disable no-useless-escape */ |
5
|
|
|
function stripTrailingSlash(str: string): string { |
6
|
|
|
return str.endsWith("/") ? str.slice(0, -1) : str; |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
function isValidUrl(str: string): boolean { |
10
|
|
|
if (str.startsWith("http://") || str.startsWith("https://")) { |
11
|
|
|
try { |
12
|
|
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars |
13
|
|
|
const url = new URL(str); |
14
|
|
|
} catch (_) { |
15
|
|
|
return false; |
16
|
|
|
} |
17
|
|
|
return true; |
18
|
|
|
} |
19
|
|
|
return false; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
export function baseUrl(): string { |
23
|
|
|
const base = document.querySelector("meta[name='base-url']"); |
24
|
|
|
if (base !== null) { |
25
|
|
|
return stripTrailingSlash(base.getAttribute("content") ?? ""); |
26
|
|
|
} |
27
|
|
|
return ""; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
export function basePathname(): string { |
31
|
|
|
const base = baseUrl(); |
32
|
|
|
return isValidUrl(base) ? new URL(baseUrl()).pathname : ""; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
export function baseApiUrl(version = 1): string { |
36
|
|
|
return `${baseUrl()}/api/v${version}`; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* |
41
|
|
|
* @param imgFile The name of the img file, not including the /images/ path. |
42
|
|
|
*/ |
43
|
|
|
export function imageUrl(imgFile: string): string { |
44
|
|
|
return `${baseUrl()}/images/${imgFile}`; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Removes the base url or base pathname if the given url starts with them. |
49
|
|
|
* @param url |
50
|
|
|
*/ |
51
|
|
|
export function removeBaseUrl(url: string): string { |
52
|
|
|
const base = baseUrl(); |
53
|
|
|
if (url.startsWith(base)) { |
54
|
|
|
return url.substr(base.length); |
55
|
|
|
} |
56
|
|
|
const basePath = basePathname(); |
57
|
|
|
if (url.startsWith(basePath)) { |
58
|
|
|
return url.substr(basePath.length); |
59
|
|
|
} |
60
|
|
|
return url; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
export function jobShow(locale: string, jobId: number): string { |
64
|
|
|
return `${baseUrl()}/${locale}/jobs/${jobId}`; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function applicationShow( |
68
|
|
|
locale: string, |
69
|
|
|
prefix: string, |
70
|
|
|
applicationId: number, |
71
|
|
|
jobId: number, |
72
|
|
|
): string { |
73
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applications/${applicationId}`; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
function applicantShow( |
77
|
|
|
locale: string, |
78
|
|
|
prefix: string, |
79
|
|
|
applicantId: number, |
80
|
|
|
jobId: number, |
81
|
|
|
): string { |
82
|
|
|
return `${baseUrl()}/${locale}/${prefix}/jobs/${jobId}/applicants/${applicantId}`; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
export function managerApplicationShow( |
86
|
|
|
locale: string, |
87
|
|
|
applicationId: number, |
88
|
|
|
jobId: number, |
89
|
|
|
): string { |
90
|
|
|
return applicationShow(locale, "manager", applicationId, jobId); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
export function managerApplicantShow( |
94
|
|
|
locale: string, |
95
|
|
|
applicantId: number, |
96
|
|
|
jobId: number, |
97
|
|
|
): string { |
98
|
|
|
return applicantShow(locale, "manager", applicantId, jobId); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
export function managerEditProfile(locale: string): string { |
102
|
|
|
return `${baseUrl()}/${locale}/manager/profile`; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
export function managerJobIndex(locale: string): string { |
106
|
|
|
return `${baseUrl()}/${locale}/manager/jobs`; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
export function managerJobSummary(locale: string, jobId: number): string { |
110
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}`; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
export function managerJobPreview(locale: string, jobId: number): string { |
114
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/preview`; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
export function managerJobApplications(locale: string, jobId: number): string { |
118
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/applications`; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
export function managerScreeningPlan(locale: string, jobId: number): string { |
122
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/assessment-plan`; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
export function applicationReviewUpdate( |
126
|
|
|
locale: string, |
127
|
|
|
applicationId: number, |
128
|
|
|
): string { |
129
|
|
|
return `${baseApiUrl()}/applications/${applicationId}/review`; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
export function jobBuilderIntro(locale: string, jobId?: number): string { |
133
|
|
|
if (jobId) { |
134
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/intro`; |
135
|
|
|
} |
136
|
|
|
return `${baseUrl()}/${locale}/manager/job-builder/intro`; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
export function jobBuilderDetails(locale: string, jobId: number): string { |
140
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/details`; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
export function jobBuilderEnv(locale: string, jobId: number): string { |
144
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/environment`; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
export function jobBuilderImpact(locale: string, jobId: number): string { |
148
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/impact`; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
export function jobBuilderTasks(locale: string, jobId: number): string { |
152
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/tasks`; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
export function jobBuilderSkills(locale: string, jobId: number): string { |
156
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/skills`; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
export function jobBuilderReview(locale: string, jobId: number): string { |
160
|
|
|
return `${baseUrl()}/${locale}/manager/jobs/${jobId}/builder/review`; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
type FaqSection = "manager-who" | "levels"; |
164
|
|
|
|
165
|
|
|
export function applicantFaq(locale: string, faqSection?: FaqSection): string { |
166
|
|
|
const base = `${baseUrl()}/${locale}/faq`; |
167
|
|
|
if (faqSection) { |
168
|
|
|
return `${base}#${faqSection}`; |
169
|
|
|
} |
170
|
|
|
return base; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
export function managerFaq(locale: string, faqSection?: FaqSection): string { |
174
|
|
|
const base = `${baseUrl()}/${locale}/manager/faq`; |
175
|
|
|
if (faqSection) { |
176
|
|
|
return `${base}#${faqSection}`; |
177
|
|
|
} |
178
|
|
|
return base; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
export function hrJobIndex(locale: string): string { |
182
|
|
|
return `${baseUrl()}/${locale}/hr/jobs`; |
183
|
|
|
} |
184
|
|
|
export function hrJobSummary(locale: string, jobId: number): string { |
185
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}`; |
186
|
|
|
} |
187
|
|
|
export function hrJobReview(locale: string, jobId: number): string { |
188
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/review`; |
189
|
|
|
} |
190
|
|
|
export function hrJobPreview(locale: string, jobId: number): string { |
191
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/preview`; |
192
|
|
|
} |
193
|
|
|
export function hrScreeningPlan(locale: string, jobId: number): string { |
194
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/assessment-plan`; |
195
|
|
|
} |
196
|
|
|
export function hrJobApplications(locale: string, jobId: number): string { |
197
|
|
|
return `${baseUrl()}/${locale}/hr/jobs/${jobId}/applications`; |
198
|
|
|
} |
199
|
|
|
export const hrApplicationShow = ( |
200
|
|
|
locale: string, |
201
|
|
|
applicationId: number, |
202
|
|
|
jobId: number, |
203
|
|
|
): string => applicationShow(locale, "hr", applicationId, jobId); |
204
|
|
|
export const hrApplicantShow = ( |
205
|
|
|
locale: string, |
206
|
|
|
applicantId: number, |
207
|
|
|
jobId: number, |
208
|
|
|
): string => applicantShow(locale, "hr", applicantId, jobId); |
209
|
|
|
|
210
|
|
|
export function accountSettings(locale: string): string { |
211
|
|
|
return `${baseUrl()}/${locale}/settings`; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
export function applicationIndex(locale: Locales): string { |
215
|
|
|
return `${baseUrl()}/${locale}/applications`; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
function baseApplicationUrl(locale: Locales, applicationId) { |
219
|
|
|
return `${baseUrl()}/${locale}/applications/${applicationId}`; |
220
|
|
|
} |
221
|
|
|
export function applicationWelcome( |
222
|
|
|
locale: Locales, |
223
|
|
|
applicationId: number, |
224
|
|
|
): string { |
225
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/welcome`; |
226
|
|
|
} |
227
|
|
|
export function applicationBasic( |
228
|
|
|
locale: Locales, |
229
|
|
|
applicationId: number, |
230
|
|
|
): string { |
231
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/basic`; |
232
|
|
|
} |
233
|
|
|
export function applicationExperienceIntro( |
234
|
|
|
locale: Locales, |
235
|
|
|
applicationId: number, |
236
|
|
|
): string { |
237
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/experience-intro`; |
238
|
|
|
} |
239
|
|
|
export function applicationExperience( |
240
|
|
|
locale: Locales, |
241
|
|
|
applicationId: number, |
242
|
|
|
): string { |
243
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/experience`; |
244
|
|
|
} |
245
|
|
|
export function applicationSkillsIntro( |
246
|
|
|
locale: Locales, |
247
|
|
|
applicationId: number, |
248
|
|
|
): string { |
249
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/skills-intro`; |
250
|
|
|
} |
251
|
|
|
export function applicationSkills( |
252
|
|
|
locale: Locales, |
253
|
|
|
applicationId: number, |
254
|
|
|
): string { |
255
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/skills`; |
256
|
|
|
} |
257
|
|
|
export function applicationFit(locale: Locales, applicationId: number): string { |
258
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/fit`; |
259
|
|
|
} |
260
|
|
|
export function applicationReview( |
261
|
|
|
locale: Locales, |
262
|
|
|
applicationId: number, |
263
|
|
|
): string { |
264
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/review`; |
265
|
|
|
} |
266
|
|
|
export function applicationSubmission( |
267
|
|
|
locale: Locales, |
268
|
|
|
applicationId: number, |
269
|
|
|
): string { |
270
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/submission`; |
271
|
|
|
} |
272
|
|
|
export function applicationNextSteps( |
273
|
|
|
locale: Locales, |
274
|
|
|
applicationId: number, |
275
|
|
|
): string { |
276
|
|
|
return `${baseApplicationUrl(locale, applicationId)}/next`; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Converts a string to a url safe equivalent. |
281
|
|
|
* @param string Any input text. |
282
|
|
|
* @returns url safe string. |
283
|
|
|
*/ |
284
|
|
|
export function slugify(string: string): string { |
285
|
|
|
const a = |
286
|
|
|
"àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;"; |
287
|
|
|
const b = |
288
|
|
|
"aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------"; |
289
|
|
|
const p = new RegExp(a.split("").join("|"), "g"); |
290
|
|
|
|
291
|
|
|
return string |
292
|
|
|
.toString() |
293
|
|
|
.toLowerCase() |
294
|
|
|
.replace(/\s+/g, "-") // Replace spaces with - |
295
|
|
|
.replace(p, (c) => b.charAt(a.indexOf(c))) // Replace special characters |
296
|
|
|
.replace(/&/g, "-and-") // Replace & with 'and' |
297
|
|
|
.replace(/[^\w\-]+/g, "") // Remove all non-word characters |
298
|
|
|
.replace(/\-\-+/g, "-") // Replace multiple - with single - |
299
|
|
|
.replace(/^-+/, "") // Trim - from start of text |
300
|
|
|
.replace(/-+$/, ""); // Trim - from end of text |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
export const getApplicantUrl = ( |
304
|
|
|
locale: Locales, |
305
|
|
|
portal: Portal, |
306
|
|
|
applicantId: number, |
307
|
|
|
jobId: number, |
308
|
|
|
): string => { |
309
|
|
|
const applicantUrlMap: { [key in typeof portal]: string } = { |
310
|
|
|
hr: hrApplicantShow(locale, applicantId, jobId), |
311
|
|
|
manager: managerApplicantShow(locale, applicantId, jobId), |
312
|
|
|
}; |
313
|
|
|
|
314
|
|
|
return applicantUrlMap[portal]; |
315
|
|
|
}; |
316
|
|
|
|
317
|
|
|
export const getApplicationUrl = ( |
318
|
|
|
locale: Locales, |
319
|
|
|
portal: Portal, |
320
|
|
|
applicationId: number, |
321
|
|
|
jobId: number, |
322
|
|
|
): string => { |
323
|
|
|
const applicationUrlMap: { [key in typeof portal]: string } = { |
324
|
|
|
hr: hrApplicationShow(locale, applicationId, jobId), |
325
|
|
|
manager: managerApplicationShow(locale, applicationId, jobId), |
326
|
|
|
}; |
327
|
|
|
|
328
|
|
|
return applicationUrlMap[portal]; |
329
|
|
|
}; |
330
|
|
|
|
331
|
|
|
const baseApplicantProfileUrl = ( |
332
|
|
|
locale: Locales, |
333
|
|
|
applicantId: number, |
334
|
|
|
): string => { |
335
|
|
|
return `${baseUrl()}/${locale}/profile/${applicantId}`; |
336
|
|
|
}; |
337
|
|
|
|
338
|
|
|
export const getApplicantExperienceUrl = ( |
339
|
|
|
locale: Locales, |
340
|
|
|
applicantId: number, |
341
|
|
|
): string => `${baseApplicantProfileUrl(locale, applicantId)}/experience`; |
342
|
|
|
|
343
|
|
|
export const getApplicantSkillsUrl = ( |
344
|
|
|
locale: Locales, |
345
|
|
|
applicantId: number, |
346
|
|
|
): string => `${baseApplicantProfileUrl(locale, applicantId)}/skills`; |
347
|
|
|
|